<?php

namespace Api\Controller;

use Think\Controller;

//加载commons下的functions.php自定义函数库
load("@.functions");

/**
 * Description of EquipmentApiController
 *
 * @author Shangyidong
 */
class FeedbackApiController extends Controller {

//用户反馈 dy_user_feedback
    //put your code here
    function add_feedback() {
        header("Content-Type: text/html; charset=utf-8");
        
        $app_key= I('get.app_key');
        verify_app_key($app_key);
        $token= I('get.token');
        $UserModel = new \Common\Model\UserModel();
        $user = $UserModel->get_user_by_token($token);
//        show_bug($user);
        if($user == null){
            $user_id = 0;
        }else{
            $user_id = $user['id'];
        }
        
        $user_feedback = D("user_feedback");
        $user_feedback->user_id = $user_id;
        $user_feedback->phone = I('get.phone');
        $user_feedback->qq = I('get.qq');
        $user_feedback->content = I('get.content');
        $user_feedback->puttime = date("Y-m-d H:i:s");
//        show_bug($user_feedback);
        $result['code'] = "200";
        if (strlen($user_feedback->content) == 0) {
            $result['code'] = "1030101"; //反馈内容不可以为空
            echo json_encode($result, JSON_PRETTY_PRINT);
            die();
        }
        if ($r = $user_feedback->add()) {
            $User_feedbackModel = new \Common\Model\User_feedbackModel();
            $user_feedback = $User_feedbackModel->where("id = ".$r)->find();
            $result['result'] = $user_feedback;
            echo json_encode($result, JSON_PRETTY_PRINT);
        } else {
            $result['code'] = "500"; //
            echo json_encode($result, JSON_PRETTY_PRINT);
        }
    }

}
